//      main.c
//
//      Copyright 2011 richard <richard@desktop>
//
//      This program is free software; you can redistribute it and/or modify
//      it under the terms of the GNU General Public License as published by
//      the Free Software Foundation; either version 2 of the License, or
//      (at your option) any later version.
//
//      This program is distributed in the hope that it will be useful,
//      but WITHOUT ANY WARRANTY; without even the implied warranty of
//      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//      GNU General Public License for more details.
//
//      You should have received a copy of the GNU General Public License
//      along with this program; if not, write to the Free Software
//      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
//      MA 02110-1301, USA.


#include "../common/common.h"

//Moves one led down and one up, value 4 is skipped so it does not look like it's pauses at the enter.
void Display1()
{
	u8 n,t;
	for(t = 0 ; t < 10 ; t++)
	{
		for( n = 0 ; n < 8 ; n = n==3?5:n+1 )
		{
			PORTB = ~((1<<n)|(1<<(7-n)));
			delay_ms(100);
		}
	}
}

//Flashes on and off, off is twice as long as on.
void Display2()
{
	u8 t;
	for( t = 0 ; t < 10 ; t++)
	{
		PORTB = 255;
		delay_ms(200);

		PORTB = 0;
		delay_ms(100);
	}
}

//Turns all LEDs on one at a time, top to bottom, then off again, top to bottom.
void Display3()
{
	u8 t,n;
	for(t = 0 ; t < 10 ; t++)
	{
		//Turn on.
		PORTB = 255;//Start all off.
		for( n = 0 ; n < 8 ; n++ )
		{
			PORTB &= ~(1<<n);
			delay_ms(100);
		}
		//Now turn off.
		for( n = 0 ; n < 8 ; n++ )
		{
			PORTB |= 1<<n;
			delay_ms(100);
		}
	}
}

//Bounces two lights top to bottom and back up.
void Display4()
{
	u8 n,t;

	for(t = 0 ; t < 10 ; t++)
	{
		//move down
		for(n= 0 ; n < 7 ; n++ )
		{
			PORTB = ~(3<<n);
			delay_ms(100);
		}
		//move dup
		for( n = 6 ; n > 0 ; n-- )
		{
			PORTB = ~(3<<n);
			delay_ms(100);
		}
	}
}

int main(void)
{
	AllOff();

	//Set all of port B as output.
	DDRB = 255;
	PORTB = 0;//Start with all off.

	/* loop forever */
	while (1)
	{
		Display1();
		Display2();
		Display3();
		Display4();
	}
}













